package cn.jbooter.shiro.autoconfigure.config;

import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;

/**
 * Shiro 注解支持配置
 * @author HeJian
 *
 */
public class ShiroAnnotationConfiguration {
	private static final Logger logger = LoggerFactory.getLogger(ShiroAnnotationConfiguration.class);
	
	@Autowired
	private SecurityManager securityManager;
	
	/**
	 * 注解的aop代理
	 * @return
	 */
	@Bean
    @DependsOn("lifecycleBeanPostProcessor")
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
		return new DefaultAdvisorAutoProxyCreator();
    }
	
	/**
	 * 开启Shiro Spring AOP权限注解的支持
	 * @param securityManager
	 * @return
	 */
    @Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor() {
    	AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
        advisor.setSecurityManager(securityManager);
        return advisor;
    }
	
}
